<?php

class Core_Action_Admin_Appearance_Menu_Item_Edit extends Action_Admin
{
	function execute($request)
	{
		$id = $request -> getParam('item_id');

		$table = Model::getTable('core/menuitem');
		$item = $table -> find($id) -> current();
		$form = Form::factory('core/admin/appearance/menu/item/edit');

		if ($request -> isGet() && $item)
		{
			$form -> setData($item -> toArray());
		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();
			$item -> setFromArray($data);
			$item -> save();
			$form -> setNotice('Saved.');
		}

		$request -> response = View::render($script = 'core/html/admin/edit', $data = array(
			'form' => $form,
			'title' => 'Edit Menu Item'
		));
	}

}
